package com.zhiwei.service;

import com.zhiwei.mapper.ProductsMapper;
import com.zhiwei.pojo.Products;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ProductsServiceImpl implements ProductsService{
    @Autowired
    private ProductsMapper productsMapper;

    public Products getProduct(Integer productId) {
        return productsMapper.selectById(productId);
    }

    @Override
    public Map<Integer, Products> getProductLists() {
        List<Products> products = productsMapper.selectList(null);
        Map<Integer, Products> productMap = new HashMap<>();
        for (Products product : products) {
            if (!productMap.containsKey(product.getId())){
                productMap.put(product.getId(),product);
            }
        }
        return productMap;
    }
}
